package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.ValidateCodeRequest;
import com.itheima.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
@Slf4j
public class MemberController {
    @Autowired
    private MemberService memberService;
    @PostMapping("/login")
    public Result login(@RequestBody ValidateCodeRequest validateCodeRequest) {
        String telephone = validateCodeRequest.getTelephone();
        Integer validateCode = validateCodeRequest.getValidateCode();
        log.info("手机号：{}", telephone);
        log.info("验证码：{}", validateCode);


        try {
            return memberService.login(telephone, validateCode);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "登录失败", null);
        }
    }
}
